package com.lsy.demo.controller;


/**
 * @author : lsy
 * @version 1.0
 * @description: TODO
 * @date 2021/8/10 11:19
 */

public class ThreadClass {

    public static class MyThread implements Runnable {
        @Override
        public void run() {
            System.out.println("-------runnable------");
        }
    }


    public static class MyThreadOne extends Thread {
        @Override
        public void run() {
            System.out.println("------- extends Thread ------");
        }

    }


    public static void main (String[] args) {
        try {
            System.out.println(MyThreadOne.currentThread().getName());
            System.out.println(MyThreadOne.currentThread().toString());
            Thread a = new Thread();
            System.out.println("我是默认线程优先级："+a.getPriority());
            Thread b = new Thread();
            b.setPriority(10);
            b.setName("90999-----");
            System.out.println("我是设置过的线程优先级："+b.getPriority());
            System.out.println("我是设置过的线程优先级："+b.toString());
            new Thread(()->{
                System.out.println("jdk1.8 ++++");
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }

         ThreadGroup threadGroup = new ThreadGroup("t1");
//        threadGroup.setMaxPriority(6);
//        Thread thread = new Thread(threadGroup,"thread");
//        thread.setPriority(9);
//
//        Thread thread1 = new Thread(threadGroup,"thread");
//        thread1.setPriority(5);
//
//        System.out.println("我是线程组的优先级"+threadGroup.getMaxPriority());
//        System.out.println("我是线程的优先级"+thread.getPriority());
//        System.out.println("我是线程1的优先级"+thread1.getPriority());

        ThreadGroup threadGroup1 = new ThreadGroup("group345") {
            // 继承ThreadGroup并重新定义以下⽅法
            // 在线程成员抛出unchecked exception
            // 会执⾏此⽅法
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println(t.getName() + ":-- " + e.getMessage());
            }
        };

        // 这个线程是threadGroup1的⼀员
        Thread thread1 = new Thread(threadGroup1, new Runnable() {
            @Override
            public void run() {
                // 抛出unchecked异常
                throw new RuntimeException("测试异常09");
            }
        });
        System.out.println(threadGroup1.getName());
        thread1.start();
//        IntStream.range(1, 10).parallel().forEach(i -> {
//            Thread thread = new Thread(new T1());
//            thread.setPriority(i);
//            thread.start();
//        });
    }



}
